<template>
	<view class="content">
		<image src="../../static/share-1.png" style="position: absolute;top:0;left: 0;width: 100%;z-index: 1;height: 100%;" mode=""></image>
		<view class="pageHeader">
			推广中心
			<a class="generalBack" @click="backpage()" hover-class="none">
			 <image src="/static/back.png" style="width: 18upx;height: 30upx;"></image>
			 </a>
		</view>
		<view style="margin: 60upx 70upx 0;position: relative;z-index: 20;">
			<view style="background-color: #fff;position: relative;border-radius: 6upx;">
				<!-- 两个球 -->
				<view class="circle circle_left"></view>
				<view class="circle circle_right"></view>
				<view class="flex aic jc-center" style="padding: 50upx;font-size: 28upx;color: #333;">
					<image :src="userinfo.avatar" style="width: 80upx;height: 80upx;border-radius: 50%;margin-right: 16upx;"></image>
					<text>{{userinfo.nickname}}</text>
				</view>
				<view style="width: 290upx;height:290upx;margin:0 auto;background-color: #fff;padding: 12upx;">
					<image :src="val" style="width: 288upx;height: 288upx;"></image>
					<!-- <tki-qrcode ref="qrcode" :val="val" :size="size" :unit="unit"  :loadMake="loadMake"/> -->
				</view>
				<button class="share"  @tap="shareWeiXin('WXSceneSession')">分享二维码</button>
				<view style="text-align: center;position: relative;font-size:30upx;padding-bottom: 80upx;">
					推广码：<text style="font-size: 34upx;color: #1D84E8;font-weight: 600;">{{userinfo.referral_code}}</text>
					<button class="copy" @click="copytxt()">复制</button>
				</view>
			</view>
			
			<view style="margin-top: 20upx;background-color: #fff;padding: 30upx;border-radius: 6upx;position: relative;" >
				<text style="position: absolute;font-size: 26upx;color: #333;left: 30upx;top:28upx">
					推广介绍:
				</text>
				<view style="padding-left: 140upx;font-size: 24upx;color: #666;">
					分享推荐其他人 获得更多权益 赶快行动吧~ 
				</view>
			</view>
		</view>
	</view>
	</template>
	<script>
	import postAjax from '../../API/postAjax.js'
	import tkiQrcode from '../../components/tki-qrcode/tki-qrcode.vue'
	export default {
		data() {
			return {
				userToken:'',// token
				userinfo:[],
				code:'',
				
				// 要生成的二维码值
				val: '三道',
				size: 288, // 二维码大小
				unit: 'upx', // 单位
				loadMake: true, // 组件加载完成后自动生成二维码
			}
		},
		onLoad(options) {
			let that = this
			that.userToken = uni.getStorageSync('token')
			that.userinfo =  uni.getStorageSync("userinfo")
			that.get_code()
		},
		methods: {
			// 返回上一页
			backpage(){
				uni.navigateBack({
					delta:1
				})
			},
			copytxt(){
				uni.setClipboardData({
				    data:this.userinfo.referral_code,
				    success: function () {
				       uni.showToast({
				         title:'复制成功',
				         icon:'none'
				       })
				    }
				});
			},
			get_code(){
				let that = this 
				postAjax('user/PromotionCenter',{token:that.userToken},function(data){
					// console.log(data)
					if(data.code==0){
						that.val = data.data.url
					}else{
						that.get_code()
					}
					
				})
			},
			shareWeiXin(scene){
				let _this = this
					let sc = scene
					_this.capture(sc)
			},
			capture(scene) {
			  let _this = this
			  let pages = getCurrentPages();
			  let page = pages[pages.length - 1];
			  console.log(pages)
			  let bitmap=null;  
			  let currentWebview = page.$getAppWebview();    
			  bitmap = new plus.nativeObj.Bitmap('amway_img');  
			  // 将webview内容绘制到Bitmap对象中  
			  currentWebview.draw(bitmap,function(){  
			      console.log('截屏绘制图片成功');  
			      // bitmap.save( "_doc/"+Math.random()+".jpg"
			      bitmap.save( "_doc/invite.jpg"
			      ,{}  
			      ,function(i){  
			          console.log('保存图片成功：'+JSON.stringify(i));
			          uni.saveImageToPhotosAlbum({  
			              filePath: i.target,  
			              success: function () {
							_this.path = i.target
			                  bitmap.clear(); //销毁Bitmap图片  
			                  uni.showToast({  
			                      title: '保存图片成功',  
			                      mask: false,  
			                      duration: 1500  
			                  }); 
							uni.share({
								provider: "weixin",
								scene: scene,
								type: 2,
								imageUrl : _this.path,
								success: function (res) {
									console.log("success:" + JSON.stringify(res));
								},
								fail: function (err) {
									console.log("fail:" + JSON.stringify(err));
								}
							});
			              } 
			          });  
			      }  
			      ,function(e){  
			          console.log('保存图片失败：'+JSON.stringify(e));  
			      });  
			  },function(e){  
			      console.log('截屏绘制图片失败：'+JSON.stringify(e));  
			  });  
			  //currentWebview.append(amway_bit);    
			}
	}
	}
</script>

<style>
	.content{min-height: 100vh;background-color: #F9F9F9;position: relative;}
	.pageHeader{position: relative;z-index: 10;width: 100%;height: 128upx;background-color: #fff;line-height: 128upx;text-align: center;font-size: 36upx;color: #333;padding-top: 40upx;}
	.generalBack{position: absolute;top:40upx;left:30upx;display: block;}
	.share{display: block;font-size: 30upx;width:270upx;padding: 0;background:#1D84E8;color: #fff;margin:30upx auto;color: #fff;border:2upx solid #1D84E8;border-radius: 8upx;}
	.copy{color: #EC6104;font-size: 26upx;padding:8upx 20upx;background:none;position: absolute;right:40upx;top:0;line-height: initial;}
	.share::after,.copy::after{border: none;}
	.regoodbox{padding:0 30upx;}
	.circle{width: 100upx;height:100upx;border-radius: 50%;background-color: #1D84E8;position: absolute;top:140upx}
	.circle_left{left:-50upx}
	.circle_right{right:-50upx}
</style>
